package com.efounder.integral;

import com.efounder.message.struct.IMStruct002;

/**
 * 处理消息中的积分相关
 */
public class JFChatIntegralManager {

    public static final String INTERGRAL = "integral";
    public static final String INTERGRAL_COUNT = "integralCount";

    /**
     * @param historyIMStruct 历史消息体
     * @param newIMStruct  新消息体
     */

    public static void handleIntegralMessage(IMStruct002 historyIMStruct, IMStruct002 newIMStruct) {
        int integral =  historyIMStruct.getExtra(INTERGRAL) == null ? 0 : (Integer) historyIMStruct.getExtra(INTERGRAL);
        int integralCount =  historyIMStruct.getExtra(INTERGRAL_COUNT) == null ? 0 :  (Integer) historyIMStruct.getExtra(INTERGRAL_COUNT);

        integral += newIMStruct.getIntegral();
        integralCount += 1;

        historyIMStruct.putExtra(INTERGRAL, integral);
        historyIMStruct.putExtra(INTERGRAL_COUNT, integralCount);
    }

}
